/* Copyright Thanh-Trung Pham, JAIST, 2012 */

package jp.ac.jaist.utility;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

/**
 *
 * @author Thanh-Trung Pham
 */
public class ReliabilityModelingLogger{
    private static final String APPLICATION_LOGGING_FILENAME = "logs/ReliabilityModeling.log";
    private static ReliabilityModelingLogger m_oReliabilityModelingLogger;
    private static Logger m_oLogger;

    /**
     * The constructor.
     */
    private ReliabilityModelingLogger() {
        initialize();
    }

    /**
     * Get the only application logging instance.
     * @return the only application logging instance.
     */
    public static synchronized ReliabilityModelingLogger getInstance(){
        if(m_oReliabilityModelingLogger == null){
            m_oReliabilityModelingLogger = new ReliabilityModelingLogger();
        }

        return m_oReliabilityModelingLogger;
    }

    /**
     * Get the logger.
     * @return the logger.
     */
    public Logger getLogger() {
        return m_oLogger;
    }

    /**
     * Initialize.
     */
    private void initialize() {
        try {
            m_oLogger = Logger.getLogger("jp.ac.jaist.util.ReliabilityModelingLogger");

            FileHandler oFileHandler = new FileHandler(APPLICATION_LOGGING_FILENAME);

            oFileHandler.setFormatter(new SimpleFormatter());
            //oFileHandler.setFormatter(new XMLFormatter());

            m_oLogger.addHandler(oFileHandler);
        } catch (IOException oIOException) {
            m_oLogger.log(Level.SEVERE, oIOException.getMessage(), oIOException);
        } catch (SecurityException oSecurityException) {
            m_oLogger.log(Level.SEVERE, oSecurityException.getMessage(), oSecurityException);
        }
    }

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#clone()
     */
    @Override
    protected Object clone() throws CloneNotSupportedException {
        throw new CloneNotSupportedException();
    }

}
